package com.weitu.emergency.service.impl;

import com.weitu.emergency.entity.EmergencyPlan;
import com.weitu.emergency.mapper.EmergencyPlanMapper;
import com.weitu.emergency.service.EmergencyPlanService;
import com.weitu.permission.dictionary.mapper.DictionaryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author zhangqingxi 2017-05-10
 */
@Service
public class EmergencyPlanServiceImpl implements EmergencyPlanService {

    private final EmergencyPlanMapper emergencyPlanMapper;

    private final DictionaryMapper dictionaryMapper;

    @Autowired
    public EmergencyPlanServiceImpl(EmergencyPlanMapper emergencyPlanMapper, DictionaryMapper dictionaryMapper) {
        this.emergencyPlanMapper = emergencyPlanMapper;
        this.dictionaryMapper = dictionaryMapper;
    }

    @Override
    public List<EmergencyPlan> findByParam(Map paramMap) {
        List<EmergencyPlan> emergencyPlanList=emergencyPlanMapper.findByParam(paramMap);
        for (EmergencyPlan emergencyPlan :emergencyPlanList){
            String typeIds=emergencyPlan.getTypeId();
            String [] typeIdArray=typeIds.split(",");
            StringBuffer sb=new StringBuffer();
            for (int i=0;i<typeIdArray.length;i++){
                sb.append(dictionaryMapper.queryDictionaryById(typeIdArray[i]).getName());
                if(i<typeIdArray.length-1){
                    sb.append(",");
                }

            }
            emergencyPlan.setTypeName(sb.toString());

        }
        return emergencyPlanList;
    }

    @Override
    public Integer findByParamCount(Map paramMap) {
        return emergencyPlanMapper.findByParamCount(paramMap);
    }

    @Override
    public EmergencyPlan findById(String id) {
        return emergencyPlanMapper.findById(id);
    }

    @Override
    public Integer add(Map paramMap) {
        return emergencyPlanMapper.add(paramMap);
    }

    @Override
    public Integer updateById(Map paramMap) {
        return emergencyPlanMapper.updateById(paramMap);
    }
}
